<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\model;

/**
 * 赌王模型
 */
class GamblerKingInvestment extends ModelBase
{
    protected $insert = ['create_time'];


    /**
     * 时间自动完成
     */
    public function setCreateTimeAttr()
    {

        return TIME_NOW;
    }


    public function getRankingAttr(){
        $total=UserKingInvestment::where(['investment_id'=>$this->id,'state'=>['lt',3]])->sum('money');
        $total=$total?$total:0;
        return $total;
    }

    public function getImageAttr(){

        return get_picture_url($this->cover_id,false);
    }

    public function getBackImageAttr(){

        return get_picture_url($this->back_cover_id,false);
    }


    /**
     * 连赌王表
     */
    public function king(){
        return $this->belongsTo('GamblerKing','king_id','id');
    }



}
